<?php
if ($action == ""){
$main_content .='
<div class="InnerTableContainer">
<table style="width:100%;">
<tbody>
<tr>
<td>
<div class="TableShadowContainerRightTop">
<div class="TableShadowRightTop" style="background-image:url('.$layout_name.'/images/content/table-shadow-rt.gif);">
</div>
</div>
<div class="TableContentAndRightShadow" style="background-image:url('.$layout_name.'/images/content/table-shadow-rm.gif);">
<div class="TableContentContainer">
<table width="100%" border="0" cellpadding="2" cellspacing="2" class="TableContent" style="border:1px solid #faf0d7;" ><tbody><tr>	
<tr bgcolor="#D4C0A1">
<td><b>Title</b></td>
<td><b>Tag</b></td>
<td><b>Date</b></td>
</tr>';
$gallery = $SQL->query("SELECT * FROM  `videos` ORDER BY `data` DESC LIMIT 25");
if($gallery->rowcount() == 0) {
$main_content .='<tr bgcolor="'.$config['site']['lightborder'].'"><td colspan="3"><center><i>No videos found.</i></center></td></tr>';
} else {
if(is_object($gallery)) {
foreach($gallery as $row) {
if(!is_int($number_of_rows / 2)) { $bgcolor = $config['site']['darkborder']; } else { $bgcolor = $config['site']['lightborder']; } $number_of_rows++;
$main_content .='
<tr bgcolor="'.$bgcolor.'">
<td width="200px"><a href="'.$row['url'].'" target="_blank">'.$row['titulo'].'</a></td>
<td width="200px">'.$row['tag'].'</td>
<td width="200px">'.date("d/m/Y, H:i:s",$row['data']).'</td>
</tr>';
}
}
}
$main_content .='
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="TableShadowContainer">
<div class="TableBottomShadow" style="background-image:url('.$layout_name.'/images/content/table-shadow-bm.gif);">
<div class="TableBottomLeftShadow" style="background-image:url('.$layout_name.'/images/content/table-shadow-bl.gif);"></div>
<div class="TableBottomRightShadow" style="background-image:url('.$layout_name.'/images/content/table-shadow-br.gif);"></div>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<br />';
if ($logged){$main_content .='<a href="index.php?subtopic=gallery&action=add">New Video</a>';}
}
if ($action == "add"){
if ($logged){
$main_content .='
<form action="index.php?subtopic=gallery&action=add_" method="post">
<input type="hidden" name="data" value="'.time().'" />
<TABLE BORDER="0" CELLSPACING="1" CELLPADDING="5" WIDTH="100%">
<tr BGCOLOR="'.$config['site']['vdarkborder'].'">
<td CLASS="white"><b>Video Add</b></td>
</tr>
<tr BGCOLOR='.$config['site']['darkborder'].'>
<td>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td><strong>Titulo</strong></td>
    <td><input type="text" id="titulo" name="titulo" /></td>
  </tr>
  <tr>
    <td><strong>Url</strong></td>
    <td><input type="text" id="url" name="url" /></td>
  </tr>
  <tr>
    <td><strong>Tag</strong></td>
    <td><select name="tag" id="tag">
<option selected="selected">(Select One)</option>
<option>War</option>
<option>Guilds</option>
<option>Others</option>
</select></td>
  </tr>
  <tr>
    <td><strong>Autor</strong></td>
    <td><select name="autor">';
$players_from_logged_acc = $account_logged->getPlayersList();
if(count($players_from_logged_acc) > 0) {
$players_from_logged_acc->orderBy('name');
foreach($players_from_logged_acc as $player) {
$main_content .= '<option>'.$player->getName().'</option>';
}
}else {
$main_content .= 'You don\'t have any character on your account.';
}
$main_content .='
</select></td>
  </tr>
  <tr>
    <td><input type="submit" value="Enviar" /></td>
    <td>&nbsp;</td>
  </tr>
</table>
</td>
</tr>
</TABLE>
</form>
';}
else{
	$link = "index.php?subtopic=gallery&action=add";
	include("login.php");
}
}
if ($action == "add_"){
$SQL->query ("INSERT INTO `videos` (`id` ,`titulo` ,`url` ,`autor` ,`data` ,`tag`) VALUES (NULL,  '$titulo',  '$url',  '$autor',  '$data',  '$tag');");
$SQL->query ("OPTIMIZE TABLE  `videos`");
$main_content .='<TABLE BORDER="0" CELLSPACING="1" CELLPADDING="5" WIDTH="100%">
<tr BGCOLOR="'.$config['site']['vdarkborder'].'">
<td CLASS="white"><b>Gallery Message</b></td>
</tr>
<tr BGCOLOR='.$config['site']['darkborder'].'>
<td><b>'.$titulo.'</b> added successfully!</td>
</tr>
</TABLE>
<br />
<form action="index.php?subtopic=gallery" method="post">
<input type="image" src="'.$layout_name.'/images/buttons/sbutton_back.gif" />
</form>
';
}
?>